<!DOCTYPE html>
<html lang="zh-CN"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>订单列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/style/admin.css" media="all">
	<link rel="stylesheet" href="/style/list.css" media="all">
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">						
				<div class="layui-inline" style="float:right">
					<button class="layui-btn layuiadmin-btn-admin" data-type="add" onclick="WinOpenAdd();">添加</button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">

            <table class="layui-hide" id="test"></table>
			
			<script type="text/html" id="barStatus">
                <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="detail"  onclick="WinStatus({{d.id}},{{d.state}})">{{d.state==1 ? '上架':'下架'}}</a>
            </script>

            <script type="text/html" id="barAudit">
                <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="detail"  onclick="WinAudit({{d.id}},{{d.audit}})">{{d.audit==1 ? '正常':'审核'}}</a>
            </script>
			
			<script type="text/html" id="barPic">
                <img src="{{d.pic}}" width="60" height="20" onclick="WinPic('{{d.pic}}');" />
            </script>

            <script type="text/html" id="barDemo">
                <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail"  onclick="WinOpenEdit({{d.id}})">编辑</a>
            </script>

        </div>
    </div>
</div>
<script src="/layui/layui.js"></script>
<script src="/layui/jquery.min.js"></script>
<script src="/js/common.js"></script>
<style>
    .layui-body{overflow-y: scroll;}	
	.laytable-cell-1-orderId{width:50px;}
</style>
<script type="text/javascript">
    var tip_index = 0;  
	function show(e)
	{
		tip_index = layer.tips($("#orderGoos"+e).html(), "#order"+e, {tips: [2, '#ddd'],time: 0,area: ['300px', 'auto'],});
	}
</script>
<script>
    var table;
    layui.use('table', function(){
        table = layui.table
            ,form = layui.form;

        var goodsId = $.getUrlParam("goodsId");
        if(goodsId==null)
        {
            goodsId= 0;
        }

        table.render({
            elem: '#test'
            ,url:'/goods?url=Spec%2FList&goodsId='+goodsId
			//,cellMinWidth:80
            ,cols: [[
                {field:'id',title:'ID'}
				,{field:'name',title:'规格名称'}
				,{field:'state',title:'状态', templet: '#barStatus', unresize: true}
                ,{field:'audit',title:'状态', templet: '#barAudit', unresize: true}
                ,{field:'pic', title:'规格图片', templet: '#barPic', unresize: true}
                ,{field:'weight',title:'重量'}
                ,{field:'share',title:'分享赠'}
                ,{field:'consumption',title:'消费赠'}
                ,{field:'price',title:'商 城 价'}
				,{field:'cost',title:'商品成本'}
				,{field:'operat',title:'运营成本'}
				,{field:'coupon',title:'购物券'}
				,{field:'vouchers',title:'代金券'}
                ,{field:'owner1',title:'一星'}
                ,{field:'owner2',title:'二星'}
                ,{field:'owner3',title:'三星'}
                ,{field:'owner4',title:'诚信'}
                ,{field:'ownerCommission',title:'微店'}
                ,{field:'activityCommission',title:'活动'}
                ,{field:'edit',title:'编辑', templet: '#barDemo', unresize: true}
            ]]
            ,id: 'testReload'
        });

        //监听表格复选框选择
        table.on('checkbox(demo)', function(obj){
            console.log(obj)
        });


    });

	/*添加商品规格*/
	function WinOpenAdd(){
		window.parent.parent.WinOpenAdd(this,"/goods/spec/add.html","添加商品规格",1350,620,1);
	}	
	
	/*编辑商品规格*/
	function WinOpenEdit(id){
		window.parent.parent.WinOpenEdit(this,"/goods/spec/edit.html?id="+id,"修改商品规格资料",1350,620,1);
	}
	
	/*删除商品规格*/
	function WinOpenDel(goodsId){
		window.parent.parent.WinOpenEdit(this,"/goods/spec/del.html?goodsId="+goodsId,"删除商品规格",340,300,1);
	}
	
	/*查看商品规格*/
	function WinOpenShow(goodsId){
		window.parent.parent.WinOpenShow("/goods/spec/show.html?goodsId="+goodsId,"查看商品规格信息",1000,500);
	}

    /*修改商品状态*/
    function WinStatus(id,state){
        layer.msg('确定修改吗？', {
            btn: ['确定', '取消']
            ,yes: function(index, layero){
                if(state==1)
                {
                    state=0;
                }
                else
                {
                    state=1;
                }
                $.ajax({
                    type: "POST",
                    url: "/goodsjson",
                    contentType: "application/json; charset=utf-8",
                    data: JSON.stringify(GetJsonDataS1(id,state)),
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        if (data.code == "000000") {
                            //alert("提交成功!!");
                            location.reload();//刷新数据
                        }
                        else {
                            alert(data.errorDetail);
                        }
                    },
                    error: function (message) {
                        alert("提交数据失败！"+message);
                    }
                });


            }
        });
    }

    function GetJsonDataS1(id,state) {
        var json = {
            "url": "Spec/Set",
            "parm":{"id":id,
                "state":state
            }
        };
        return json;
    }
	
	/*查看商品图片*/
	function WinPic(pic){
		layer.msg("<img src='"+pic+"' width='300' height='300' />");
	}

    /**
     *
     * 添加商品规格
     *
     */
    function Add(body)
    {
        var goodsId = $.getUrlParam("goodsId");
        if(goodsId==null)
        {
            alert("参数错误!!");
            return 0;
        }
        var goodsName = $.getUrlParam("goodsName");
        if(goodsName==null)
        {
            alert("参数错误!!");
            return 0;
        }
        goodsName=escape(goodsName);
        var name = body.find("#name").val();
        var code = body.find("#code").val();
        var weight = body.find("#weight").val();
        var state = body.find("#state").val();
        var ulimit = body.find("#ulimit").val();
        var sumlimit = body.find("#sumlimit").val();

        var supplierprice = body.find("#supplierprice").val();
        var activitySelf = body.find("#activitySelf").val();
        var ownerCommission = body.find("#ownerCommission").val();
        var activityCommission = body.find("#activityCommission").val();
        var pic = body.find("#pic").val();

        var price = body.find("#price").val();
        var cost = body.find("#cost").val();
        var operat = body.find("#operat").val();
        var share = body.find("#share").val();
        var consumption = body.find("#consumption").val();
        var coupon = body.find("#coupon").val();
        var vouchers = body.find("#vouchers").val();
        var owner1 = body.find("#owner1").val();
        var owner2 = body.find("#owner2").val();
        var owner3 = body.find("#owner3").val();
        var owner4 = body.find("#owner4").val();

        var operator = body.find("#operator").val();
        var operations = body.find("#operations").val();
        var operationsPrice = body.find("#operationsPrice").val();
        var operatorPrice = body.find("#operatorPrice").val();
        var redEnvelope = body.find("#redEnvelope").val();
        var aloeVeraShop = body.find("#aloeVeraShop").val();
        var CooperationPrice = body.find("#CooperationPrice").val();
        var PreferentialPrice = body.find("#PreferentialPrice").val();
        var PreferentialLimited = body.find("#PreferentialLimited").val();
        var bookingPrice = body.find("#bookingPrice").val();
        var bookingLimited = body.find("#bookingLimited").val();

        var json = {
            "url": "Spec/Add",
            "parm":{"name":name,
                "code":code,
                "goodsId":goodsId,
                "goodsName":goodsName,
                "weight":weight,
                "state":state,
                "ulimit":ulimit,
                "sumlimit":sumlimit,
                "supplierprice":supplierprice,
                "activitySelf":activitySelf,
                "ownerCommission":ownerCommission,
                "activityCommission":activityCommission,
                "pic":pic,
                "price":price,
                "cost":cost,
                "operat":operat,
                "share":share,
                "consumption":consumption,
                "coupon":coupon,
                "vouchers":vouchers,
                "owner1":owner1,
                "owner2":owner2,
                "owner3":owner3,
                "owner4":owner4,
                "operator":operator,
                "operations":operations,
                "operationsPrice":operationsPrice,
                "operatorPrice":operatorPrice,
                "redEnvelope":redEnvelope,
                "aloeVeraShop":aloeVeraShop,
                "CooperationPrice":CooperationPrice,
                "PreferentialPrice":PreferentialPrice,
                "PreferentialLimited":PreferentialLimited,
                "bookingPrice":bookingPrice,
                "bookingLimited":bookingLimited
            }
        };

        $.ajax({
            type: "POST",
            url: "/goodsjson",
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(json),
            dataType: "json",
            async: false,
            success: function (data) {
                if (data.code == "000000") {
                    //alert("提交成功!!");
                    location.reload();//刷新数据
                }
                else {
                    alert(data.errorDetail);
                }
            },
            error: function (message) {
                alert("提交数据失败！"+message);
            }
        });
        return true;
    }

    /**
     *
     * 添加商品规格
     *
     */
    function Edit(body)
    {
        var id = body.find("#id").val();
        var name = body.find("#name").val();
        var code = body.find("#code").val();
        var weight = body.find("#weight").val();
        var state = body.find("#state").val();
        var ulimit = body.find("#ulimit").val();
        var sumlimit = body.find("#sumlimit").val();

        var supplierprice = body.find("#supplierprice").val();
        var activitySelf = body.find("#activitySelf").val();
        var ownerCommission = body.find("#ownerCommission").val();
        var activityCommission = body.find("#activityCommission").val();
        var pic = body.find("#pic").val();

        var price = body.find("#price").val();
        var cost = body.find("#cost").val();
        var operat = body.find("#operat").val();
        var share = body.find("#share").val();
        var consumption = body.find("#consumption").val();
        var coupon = body.find("#coupon").val();
        var vouchers = body.find("#vouchers").val();
        var owner1 = body.find("#owner1").val();
        var owner2 = body.find("#owner2").val();
        var owner3 = body.find("#owner3").val();
        var owner4 = body.find("#owner4").val();

        var operator = body.find("#operator").val();
        var operations = body.find("#operations").val();
        var operationsPrice = body.find("#operationsPrice").val();
        var operatorPrice = body.find("#operatorPrice").val();
        var redEnvelope = body.find("#redEnvelope").val();
        var aloeVeraShop = body.find("#aloeVeraShop").val();
        var CooperationPrice = body.find("#CooperationPrice").val();
        var PreferentialPrice = body.find("#PreferentialPrice").val();
        var PreferentialLimited = body.find("#PreferentialLimited").val();
        var bookingPrice = body.find("#bookingPrice").val();
        var bookingLimited = body.find("#bookingLimited").val();

        var json = {
            "url": "Spec/Set",
            "parm":{"id":id,
                "name":name,
                "code":code,
                "weight":weight,
                "state":state,
                "ulimit":ulimit,
                "sumlimit":sumlimit,
                "supplierprice":supplierprice,
                "activitySelf":activitySelf,
                "ownerCommission":ownerCommission,
                "activityCommission":activityCommission,
                "pic":pic,
                "price":price,
                "cost":cost,
                "operat":operat,
                "share":share,
                "consumption":consumption,
                "coupon":coupon,
                "vouchers":vouchers,
                "owner1":owner1,
                "owner2":owner2,
                "owner3":owner3,
                "owner4":owner4,
                "operator":operator,
                "operations":operations,
                "operationsPrice":operationsPrice,
                "operatorPrice":operatorPrice,
                "redEnvelope":redEnvelope,
                "aloeVeraShop":aloeVeraShop,
                "CooperationPrice":CooperationPrice,
                "PreferentialPrice":PreferentialPrice,
                "PreferentialLimited":PreferentialLimited,
                "bookingPrice":bookingPrice,
                "bookingLimited":bookingLimited
            }
        };
        alert(json);
        $.ajax({
            type: "POST",
            url: "/goodsjson",
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(json),
            dataType: "json",
            async: false,
            success: function (data) {
                if (data.code == "000000") {
                    //alert("提交成功!!");
                    location.reload();//刷新数据
                }
                else {
                    alert(data.errorDetail);
                }
            },
            error: function (message) {
                alert("提交数据失败！"+message);
            }
        });
        return true;
    }

</script>


</body>
</html>